package com.java.demo.service;

import com.java.demo.dao.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-07-19
 * Time: 16:05
 */
@Service
public class UserService {

    //1.属性注入
    @Autowired //DI 依赖注入
    private UserRepository userRepository;
    public int add() {
        System.out.println("do UserService method");
        //传统写法
//        UserRepository userRepository = new UserRepository();
//        return userRepository.add();

        //spring
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config");
//        UserRepository userRepository = context.getBean("userRepository", UserRepository.class);
//        return userRepository.add();

        return userRepository.add();
    }


}
